import { defineStore } from 'pinia'

export const useCounterStore = defineStore('counter', {
  state: () => ({
    count: 0,
    uavId: '',
    nestId: '',
    videoUrl: '',
    uavVideoUrl: 'null',
    nestVideoUrl: 'null'
  }),
  getters: {
    doubleCount: (state) => state.count * 2
  },
  actions: {
    increment () {
      this.count++
    },
    setUavId (id) {
      this.uavId = id
    },
    setNestId (id) {
      this.nestId = id
      setTimeout(() => {
        this.setUavId('UavId-001')
        this.uavVideoUrl = this.getVideoUrl(this.uavId)
        this.nestVideoUrl = this.getVideoUrl(this.nestId)
      }, 3000);
    },
    setVideoUrl (url) {
      this.videoUrl = url
    },
    getVideoUrl (url) {
      setTimeout(() => {
        return `webrtc://183.234.52.92:9907/index/api/webrtc?app=pinggu&stream=${url}&type=play`
      }, 1000);
    }
  }
})